package com.meixiang.activity.account;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.activity.account.storesmanager.StoresListActivity;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.tool.Tool;
import com.meixiang.util.AbToastUtil;
import com.meixiang.view.ClearEditText;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 绑定会员卡
 * author：wangzuzhen on 2016/5/6 0006 10:33.
 */
public class BindMemberCardActivity extends BaseActivity {

    /**
     * 会员卡号
     */
    @Bind(R.id.ce_input_card_number)
    ClearEditText mCeInputCardNumber;
    /**
     * 身份证号
     */
    @Bind(R.id.ce_input_identity_number)
    ClearEditText mCeInputIdentityNumber;
    /**
     * 确定
     */
    @Bind(R.id.tv_confrim)
    TextView mTvConfrim;



    /**
     * 确定
     */
    @Bind(R.id.tv_Applymembershipcards)
    TextView tv_Applymembershipcards;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_bind_member_card);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        setTitle("绑定会员卡");
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void setData() {

    }


    //yangdecheng 20160921 增加会员卡申请功能
    @OnClick({R.id.tv_confrim,R.id.tv_Applymembershipcards})
    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.tv_Applymembershipcards:

                AbToastUtil.showToast(context, "会员卡申请正在建设中");
                Intent intent =new Intent(BindMemberCardActivity.this,StoresListActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_confrim:

                if (TextUtils.isEmpty(mCeInputCardNumber.getText().toString().trim())) {
                    AbToastUtil.showToast(context, "请输入会员卡号");
                    return;
                }
                if (Tool.validatePersonalId(mCeInputCardNumber.getText().toString().trim())) {
                    AbToastUtil.showToast(context, "请输入正确的身份证号");
                    return;
                }
                getSave();

                break;
        }

    }


    private void getSave() {
        HttpParams params = new HttpParams();
        params.put("cardNum", mCeInputCardNumber.getText().toString());
        params.put("idCard", mCeInputIdentityNumber.getText().toString());
        HttpUtils.post(Config.SERVER_URL + "memberCard/api/save", params, new HttpCallBack(this) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                if ("0".equals(code)) {
                    finish();
                }else {
                    AbToastUtil.showToast(context, message);
                }
            }

            @Override
            public void onError(String code, String message) {
                AbToastUtil.showToast(context, message);
            }
        });
    }
}
